/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.hcht.xrlh.rwfz.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.hcht.xrlh.rwfz.entity.DrRwXz;
import com.hcht.xrlh.rwfz.service.DrRwXzService;

/**
 * 任务分组Controller
 * @author lrz
 * @version 2016-12-22
 */
@Controller
@RequestMapping(value = "${adminPath}/rwfz/drRwXz")
public class DrRwXzController extends BaseController {

	@Autowired
	private DrRwXzService drRwXzService;
	
	@ModelAttribute
	public DrRwXz get(@RequestParam(required=false) String id) {
		DrRwXz entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = drRwXzService.get(id);
		}
		if (entity == null){
			entity = new DrRwXz();
		}
		return entity;
	}
	
	@RequiresPermissions("rwfz:drRwXz:view")
	@RequestMapping(value = {"list", ""})
	public String list(DrRwXz drRwXz, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<DrRwXz> page = drRwXzService.findPage(new Page<DrRwXz>(request, response), drRwXz); 
		model.addAttribute("page", page);
		return "xrlh/rwfz/drRwXzList";
	}

	@RequiresPermissions("rwfz:drRwXz:view")
	@RequestMapping(value = "form")
	public String form(DrRwXz drRwXz, Model model) {
		model.addAttribute("drRwXz", drRwXz);
		return "xrlh/rwfz/drRwXzForm";
	}

	@RequiresPermissions("rwfz:drRwXz:edit")
	@RequestMapping(value = "save")
	public String save(DrRwXz drRwXz, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, drRwXz)){
			return form(drRwXz, model);
		}
		drRwXzService.save(drRwXz);
		addMessage(redirectAttributes, "保存任务分组成功");
		return "redirect:"+Global.getAdminPath()+"/rwfz/drRwXz/?repage";
	}
	
	@RequiresPermissions("rwfz:drRwXz:edit")
	@RequestMapping(value = "delete")
	public String delete(DrRwXz drRwXz, RedirectAttributes redirectAttributes) {
		drRwXzService.delete(drRwXz);
		addMessage(redirectAttributes, "删除任务分组成功");
		return "redirect:"+Global.getAdminPath()+"/rwfz/drRwXz/?repage";
	}

}